package ozu.project.State;
import ozu.project.OzuBattle;
import ozu.project.RiskTurkey;
import ozu.project.SliderPane;

import ozu.project.regions.OzuRegion;


public class AttackState extends AbstractState {

    public AttackState(RiskTurkey parent) {
        super(parent);
    }

    @Override
    public void onRegionClick(OzuRegion region) {
        if (this.risk.hasFocused()){
            if (this.risk.getFocused().equals(region)){
                this.risk.resetFocus();
            }
            else if (!risk.getActivePlayer().equals(region.getOwner())){
                OzuRegion attacker = this.risk.getFocused();
                if (attacker.isNeighbour(region)){
                    SliderPane slider = new SliderPane(0, attacker.getArmySize()-1, "Select amount to attack with: ");
                    int armySize = slider.getValue();
                    OzuBattle battle = new OzuBattle(attacker, armySize, region);
                    battle.runBattle();
                    this.risk.resetFocus();
                }
            }
        }
        else if (this.risk.getActivePlayer().equals(region.getOwner())) {
            this.risk.setFocused(region);
        }
    }

    @Override
    public boolean isRelevantNeighbour(OzuRegion focused, OzuRegion neighbour) {
        return focused.getNeighbours().contains(neighbour) &&
                !focused.getOwner().equals(neighbour.getOwner());
    }
}
